<?php
/**
 * 刮刮乐模块
 * 
 * BY:拥抱 && k7gxn56
 *
 * QQ:572300808 && 799590989
 */
defined('IN_IA') or exit('Access Denied');

class YyyModuleProcessor extends WeModuleProcessor {
	
	public $name = 'YyyModuleProcessor';

	public function isNeedInitContext() {
		return 0;
	}
	
	public function respond() {
		global $_W;
		$rid = $this->rule;
		$sql = "SELECT * FROM " . tablename('yyy_reply') . " WHERE `rid`=:rid LIMIT 1";
		$row = pdo_fetch($sql, array(':rid' => $rid));
		if (empty($row['id'])) {
			return array();
		}
		$now = time();
		if($now >= $row['start_time'] && $now <= $row['end_time']){
			$response['FromUserName'] = $this->message['to'];
			$response['ToUserName'] = $this->message['from'];
			$response['MsgType'] = 'news';
			$response['ArticleCount'] = 1;
			$response['Articles'] = array();
			$response['Articles'][] = array(
				'Title' => $row['title'],
				'Description' => $row['description'],
				'PicUrl' => $_W['attachurl'] . $row['picture'],
				'Url' => $_W['siteroot'] . create_url('index/module', array('do' => 'yyy', 'name' => 'yyy', 'id' => $rid, 'from_user' => base64_encode(authcode($this->message['from'], 'ENCODE')))),
				'TagName' => 'item',
			);
		}else{
			$response['FromUserName'] = $this->message['to'];
			$response['ToUserName'] = $this->message['from'];
			$response['MsgType'] = 'news';
			$response['ArticleCount'] = 1;
			$response['Articles'] = array();
			$response['Articles'][] = array(
				'Title' => $row['title'],
				'Description' => $row['description'],
				'PicUrl' => $_W['attachurl'] . $row['end_picture'],
				'Url' => $_W['siteroot'] . create_url('index/module', array('do' => 'yyy', 'name' => 'yyy', 'id' => $rid, 'from_user' => base64_encode(authcode($this->message['from'], 'ENCODE')))),
				'TagName' => 'item',
			);
		}
		return $response;
	}

	public function isNeedSaveContext() {
		return false;
	}
}
